onload = () => {
    loadCSS("../css/fontello.css", "bootstrap5-icon");
    loadCSS("../css/bootstrap5.min.css", "bootstrap5");
    loadScript("../js/bootstrap5.bundle.min.js").then(() => loadScript("../js/crud.js")).then(() => {
        let exchangeRateOperator = new Crud({
            module: "exchangeRate",
            hasCheckbox: true,
            iterators: [],
            opsButton: ["new"],
            search: [{"caption": "Code", "type": "text", "name": "source", class: "col-3"},
                {"caption": "Code", "type": "date", "name": "startTime", class: "col-3"}],
            listField: [{"caption": "ID", "field": "exchangeRateId"}, {
                "caption": "Source",
                "field": "source"
            }, {"caption": "Target", "field": "target"},
                {"caption": "value", "field": "value",format:str=>(str/10000).toFixed(4)}, {
                    "caption": "period",
                    "field": item => item.startTime.substring(0, 10) + " to " + item.endTime.substring(0, 10)
                },],
            editFields: [
                {caption: "Source Currency", "name": "source", "required": "required"},
                {"caption": "Target Currency", name: "target", "required": "required"},
                {"caption": "Value", name: "value", "required": "required"},
                {"caption": "Start Time", name: "startTime", type: "date", "required": "required"},
                {"caption": "End Time", name: "endTime", type: "date", "required": "required"},
            ],
            saveConverter:function(data){
                data.value = (data.value * 10000).toFixed(0);
            }
        });
        exchangeRateOperator.init()
    }).catch((err) => console.error(err));
}
